"use strict";
var _lessonid = null;
var _phase = null;
var _lessonStatus='';
$(function () {
    var params = getParamsFromUrl();
    _lessonid = params[0];
    _phase = params[1];
   
    getLessonHttp(_lessonid, _phase);
});

function getParamsFromUrl() {
    var url = decodeURI(location.href);
    var urlParmListStr = url.substr(url.indexOf('?') + 1, url.length);
    var params = urlParmListStr.split("&");
    var param1 = params[0].split("=")[1];
    var param2 = params[1].split("=")[1];
    return [param1, param2];
}

function fillLessonLearnCont(theLesson) {

    $("#lessonTitle").html(theLesson.lessonname);
    $("#lessonContent").html(theLesson.description);
    $("#lessonImg").attr('src', theLesson.image);
    $("#lessonTeacherName").append(theLesson.ownername);
    $("#lessonPhase").append(theLesson.phase);
    if(getCurrentLang()=='zh'){
     $("#lessonStatus").append(theLesson.modenamecn);
     _lessonStatus=theLesson.modenamecn;
    }
    else{
        $("#lessonStatus").append(theLesson.modenameen);
        _lessonStatus=theLesson.modenameen;
    }
    var labs = theLesson.labs;
    var labsHtml = "";
  
//   switch(theLesson.currentnb){
//       case 1:$('#onlineMap').hide();$('#onlineCode').hide();$('#themeMap').hide();break;//桌面制图
//       case 2:$('#onlineCode').hide();$('#themeMap').hide();break;//在线制图
//       case 3:$('#onlineMap').hide();$('#themeMap').hide();break;//在线开发
//       case 4:$('#onlineMap').hide();$('#onlineCode').hide();break;//专题制图
//       case 99:$('#onlineMap').hide();$('#onlineCode').hide();$('#themeMap').hide();break;//其他
//       default:break;
//   }
    $("#lessonLabsUl").html(labsHtml);
    for (var i in labs) {
        var thelab = labs[i];
        var li = $("<li class=\"media\"><h4>" + thelab.name + "</h4><p>" + thelab.description + "</p></li>");

        if (thelab.labresources.length > 0) {
            li.append("<table  class=\"table table-hover table-bordered  tabstyle\"><thead><tr><th>" + langThis("lab_labdata") + "</th><th>" + langThis("lab_labmethd") + "</th></tr></thead><tbody   class=\"itemTbody\"><tr><td class='dataTd'></td><td class='docTd'></td></tr></tbody></table>");
            var td_data = li.find('td.dataTd');
            var td_doc = li.find('td.docTd');

            for (var j in thelab.labresources) {
                var theSource = thelab.labresources[j];
                if (theSource.type == "data") {
                    td_data.append("<a  role=\"button\" class=\"btn btn-link\" href=\"" + theSource.url + "\" target=\"_balnk\">" + theSource.name + "</a>");
                    td_data.append("<span>/</span>");
                } else {
                    td_doc.append("<a  role=\"button\" class=\"btn btn-link\" href=\"" + theSource.url + "\" target=\"_balnk\">" + theSource.name + "</a>");
                    td_doc.append("<span>/</span>");
                }
            }
            td_data.find('span').last().remove();
            td_doc.find('span').last().remove();
        }
        $("#lessonLabsUl").append(li);
    }
}

function getLessonHttp(id, phase) {
    var _url = "publishlessons/" + id + "/" + phase + "/lessoninfo";
    $.ajax({
        url: _url,
        type: "GET",
        data: {},
        dataType: "json",
        success: function (data) {
            if (data != undefined && data != null) {

                fillLessonLearnCont(data);


            } else {

            }

        },
        error: function (event) {


        }
    });

}
function examineLesson(status){
   var modeid=status;
    var _url = "publishlessons/" + _lessonid + "/" + _phase + "/changemode";
    $.ajax({
        url: _url,
        type: "POST",
        contentType: "application/json",
        data: JSON.stringify({
				"modeid": modeid
			}),
        dataType: "json",
        success: function (data) {
            if (data != undefined && data != null) {
                
                       
              
                     layer.msg(langThis("nv_exm_scuss"));
                     setTimeout(function(){
                         location.reload();
                     },300 );


            } else {
                    layer.msg(langThis("nv_exm_fail"));
            }

        },
        error: function (event) {
            console.error(event);
       
        }
    });
}